package com.test;


import com.el.bean.Boss;
import com.el.bean.Car;
import com.el.bean.Color;
import com.el.bean.Yellow;
import com.el.config.MainConfigProfile;
import com.el.config.MainConifgOfAutowired;
import com.el.dao.BookDao;
import com.el.service.BookService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;


public class IOCTest_Profile {
	//1.使用命令行动态参数：-Dspring.profiles.active=环境名称（在虚拟机参数位置）
	//2.使用代码方式
	@Test
	public void test01(){
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
		//1.创建一个applicationContext
		//2.设置需要激活的环境
		applicationContext.getEnvironment().setActiveProfiles("test","dev");
		//3.注册主配置类
		applicationContext.register(MainConfigProfile.class);
		//4.启动刷新容器
		applicationContext.refresh();
		String[] beanNamesForType = applicationContext.getBeanNamesForType(DataSource.class);
		for(String name:beanNamesForType){
			System.out.println("数据源名称："+name);
		}
		Yellow bean = applicationContext.getBean(Yellow.class);
		applicationContext.close();
	}

}
